package com.diaohw.module.system.mapper;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.diaohw.module.system.obj.entity.Department;
import com.diaohw.module.system.obj.query.DepartmentQuery;
import com.diaohw.module.system.obj.tables.DepartmentDef;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
/**
 * 部门 映射层。
 *
 * @author D-Hw
 * @since 2024-11-15 18:22:15
 */
@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {


    static QueryWrapper createWrapper(DepartmentQuery query){
       QueryWrapper wrapper = QueryWrapper.create();
       wrapper.and(DepartmentDef.DEPARTMENT.STATE.eq(query.getState()).when(ObjUtil.isNotNull(query.getState())));
       wrapper.and(DepartmentDef.DEPARTMENT.PARENT_ID.eq(query.getParentId()).when(StrUtil.isNotBlank(query.getParentId())));
       wrapper.and(DepartmentDef.DEPARTMENT.DEPARTMENT_NAME.eq(query.getDepartmentName()).when(StrUtil.isNotBlank(query.getDepartmentName())));
       return wrapper;
   }
}
